#!/bin/bash
# from https://gist.github.com/digitaljhelms/f74eaf56835262d6bf3f
echo "[post rewrite hook: $1]"

# quick script to call "git submodule update" automatically if the
# .gitmodules file is changed

changedfiles=( `git diff-tree --no-commit-id --name-only HEAD@{1} HEAD` )

if [[ "${changedfiles[*]}" =~ ".gitmodules" ]]; then
    echo "initializing & updating submodule(s)"
    git submodule update --init --recursive
fi
